stage.set_background("halfcourt")
sprite = codesters.Sprite("player1")
sprite.go_to(-175, -150)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
stage.set_gravity(10)
sprite.set_gravity_off()
def click(sprite):
ball = codesters.Sprite("basketball")
ball.go_to(-175, -125)
ball.set_x_speed(10)
ball.set_y_speed(10)
# add other actions...
sprite.event_click(click)
stage.disable_right_wall()
def collision(net, hit_sprite):
my_var = hit_sprite.get_image_name()
if my_var == "basketball":
sprite.say("Score!")
# add any other actions...
net.event_collision(collision)
t = codesters.Teacher()
hides = t.find_function("hide")
try:
tval1 = hides[0][1]
tval2 = t.get_indent_at_line(hides[0][0])
except:
tval1 = "DNE"
tval2 = "DNE"
t1 = TestObjective()
t1.add_success("hit_sprite." in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you drag in Hide inside of your if statement?")
t1.add_failure("hit_sprite." not in tval1, "Did you change the name in front from sprite to hit_sprite?")
t2 = TestObjective()
t2.add_success(tval2 == 8, "Great job!")
t2.add_failure(tval2 < 8, 'Oops! Did you forget to indent your .hide() command twice?')
t2.add_failure(tval2 > 8, 'Oops! Did you indent your .hide() command too many times?')
t2.add_failure(tval2 == "DNE", 'Did you drag in Hide inside your if statement?')
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)